package com.sunlight.controller;

import com.alibaba.fastjson.JSONObject;
import com.sunlight.service.UserServiceConsumer;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;

/**
 * Created by Nicholas on 16/10/24.
 */
@Controller
public class UserController {
    @Resource
    private UserServiceConsumer userServiceConsumer;

    @RequestMapping(value = "/get/{id}",method = RequestMethod.GET)
    @ResponseBody
    public JSONObject getUserById(@PathVariable("id") int id){
        return userServiceConsumer.getUser(id);
    }

    @RequestMapping(value="/add/user",method = RequestMethod.POST)
    @ResponseBody
    public String addUser(@RequestBody JSONObject jsonObject){
        return userServiceConsumer.addUser(jsonObject);
    }

    @RequestMapping(value="/update/user",method = RequestMethod.PUT)
    @ResponseBody
    public String updateUser(@RequestBody JSONObject jsonObject){
        return userServiceConsumer.updateUser(jsonObject);
    }

    @RequestMapping(value="/delete/user/{id}",method = RequestMethod.DELETE)
    @ResponseBody
    public String deleteUser(@PathVariable("id") int id){
        return userServiceConsumer.deleteUser(id);
    }

}
